/*
 * VecRGB.h
 *
 *  Created on: Jan 1, 2011
 *      Author: burek
 */

#ifndef VECRGB_H_
#define VECRGB_H_

#include "Vec3D.h"

struct VecRGB
{
    float R, G, B;

    inline VecRGB( void ) {}
    inline VecRGB( const float x, const float y, const float z )
    { R = x; G = y; B = z; }

    inline VecRGB operator = ( const VecRGB& A )
    { R = A.R; G = A.G; B = A.B; return *this; }

    inline bool operator == ( const VecRGB& A ) const
    { return R == A.R && G == A.G && B == A.B; }

    inline VecRGB operator + ( const VecRGB& A ) const
    { return VecRGB( R + A.R, G + A.G, B + A.B ); }

    inline VecRGB operator - ( const VecRGB& A ) const
    { return VecRGB( R - A.R, G - A.G, B - A.B ); }

    inline VecRGB operator + ( const float A ) const
    { return VecRGB( R + A, G + A, B + A ); }

    inline VecRGB operator * ( const float A ) const
    { return VecRGB( R * A, G * A, B * A ); }

    inline VecRGB operator / ( const float A ) const
    { return VecRGB( R / A, G / A, B / A ); }

    inline float Dot( const VecRGB& A ) const
    { return A.R*R + A.G*G + A.B*B; }

    inline float Length( void ) const
    { return sqrt(R * R + G * G + B * B); }

    inline VecRGB Normalize(void) const
    {
    	float len = Length();
    	return VecRGB(R / len, G / len, B / len);
    }

    inline Vec3D toVec3D() const
    { return Vec3D(R,G,B); }

    inline void NormalizeIP(void)
	{
		float len = Length();
		R /= len; G /= len; B /= len;
	}

    inline void colorize(const VecRGB & rgb)
    { R *= rgb.R; G *= rgb.G; B *= rgb.B; }

    inline void set(float r, float g, float b)
    { R = r; G = g; B = b; }

    inline void operator += ( const VecRGB& A )
    { R += A.R; G += A.G; B += A.B; }

    inline void operator += ( const float A )
    { R += A; G += A; B += A; }

    inline void operator -= ( const float A )
    { R -= A; G -= A; B -= A; }

    inline void operator -= ( const VecRGB& A )
    { R -= A.R; G -= A.G; B -= A.B; }

    inline void operator *= ( const float A )
    { R *= A; G *= A; B *= A; }
};

#endif /* VECRGB_H_ */
